home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_012 / setalternate / setalternate.c < prev   
C/C++ Source or Header  |  1992-05-06  |  3KB  |  85 lines

  1. /* SetAlternate.c */
  2. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  3. /* (c) Copyright 1986 John A. Toebes, VIII   All rights reserved         */
  4. /*     120-H Northington Place,   Cary NC 27511   (919) 469-4210         */
  5. /*  This program may be used and modified for any purpose so long as     */
  6. /*  this copyright notice remains with the code and the program is not   */
  7. /*  sold and no charge is made for its use.                              */
  8. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9. #include <stdio.h>
  10. #include <exec/types.h>
  11. #include <workbench/workbench.h>
  12. #include <workbench/icon.h>
  13. #include <workbench/startup.h>
  14.  
  15. int IconBase;
  16. extern struct WBStartup *WBenchMsg;
  17.  
  18. main(argc,argv)
  19. int argc;
  20. char *argv[];
  21. {
  22.     struct DiskObject *diskobja, *diskobj, *GetDiskObject();
  23.     APTR saveimage;
  24.     USHORT saveflags;
  25.  
  26.     /* make sure we ran from CLI */
  27.     if (argc == 0) exit(1);
  28.  
  29.     /* make sure they specified two icons */
  30.     if (argc != 3)
  31.         {
  32.         printf("Usage: %s <icon> <icona>\n", argv[0]);
  33.         exit(2);
  34.         }
  35.  
  36.     /* make the icon library available to us */
  37.     if ( (IconBase = OpenLibrary( ICONNAME, 1)) == NULL)
  38.         exit(2);
  39.  
  40.     /* read the icon to modify from disk */
  41.     if ( (diskobj = GetDiskObject(argv[1])) == NULL)
  42.         {
  43.         printf("Cannot read icon for %s\n", argv[1]);
  44.         CloseLibrary( IconBase );
  45.         exit(3);
  46.         }
  47.  
  48.     /* read the second icon to get its image */
  49.     if ( (diskobja = GetDiskObject(argv[2])) == NULL)
  50.         {
  51.         printf("Cannot read icon for %s\n", argv[1]);
  52.         FreeDiskObject(diskobj);
  53.         CloseLibrary( IconBase );
  54.         exit(4);
  55.         }
  56.  
  57.     /* remember what the original icon looked like */
  58.     /* we will restore it before we do a FreeDiskObject on it */
  59.     /* this way the system won't get confused as to which memory it */
  60.     /* allocated for the structure */
  61.     saveimage = diskobj->do_Gadget.SelectRender;
  62.     saveflags = diskobj->do_Gadget.Flags;
  63.  
  64.     /* point the alternate image of the modified icon to that of the */
  65.     /* second icon */
  66.     diskobj->do_Gadget.SelectRender = diskobja->do_Gadget.GadgetRender;
  67.  
  68.     /* modify the flags so that it used the alternate image */
  69.     diskobj->do_Gadget.Flags = (saveflags & ~GADGHIGHBITS) | GADGHIMAGE;
  70.  
  71.     /* now write the fixed icon to disk */
  72.     if (!PutDiskObject( argv[1], diskobj))
  73.         printf("Cannot write new icon - code %d\n", IoErr() );
  74.  
  75.  
  76.     /* restore the original icon to what we read in */
  77.     diskobj->do_Gadget.SelectRender = saveimage;
  78.     diskobj->do_Gadget.Flags = saveflags;
  79.  
  80.     /* and send it and the other object away */
  81.     FreeDiskObject( diskobj );
  82.     FreeDiskObject( diskobja );
  83.     CloseLibrary( IconBase );
  84. }
  85.